package net.googlecode.demenkov.task4.utils;

import net.googlecode.demenkov.task4.source.StringUtil;

import static java.lang.Character.toUpperCase;

/**
 * StringUtil that normalise string: first letter in uppercase, delete extraspaces,
 * makes normal case.
 *
 * @author Yura Demenkov
 * @since 04.04.11
 */
public class StringNormalizer extends StringUtil {

    /**
     * Constructor that create StringUtil and assosiate it with inputstring.
     *
     * @param inputstring
     */
    public StringNormalizer(String inputstring) {
        super(inputstring);
    }

    /**
     * Normalise string and log this action.
     *
     * @return Corrected string.
     */
    public String NormaliseString() {
        String outputString = new String();
        StringBuilder sb = new StringBuilder();
        sb.append(toUpperCase(inputString.charAt(0)));
        sb.append(inputString.substring(1).toLowerCase());
        outputString = sb.toString();
        outputString = outputString.replaceAll("\\s+", " ").trim();
        this.LogMessage(outputString, "Normalise input string.");
        return outputString;
    }

}
